package com.soft.face.global;

import lombok.Data;

@Data
public class R<T> {

    private int code = -1;
    private String message = "操作成功";
    private T data;

    public static <T> R<T> success() {
        return r(null, 0, "操作成功");
    }

    public static <T> R<T> success(T data) {
        return r(data, 0, "操作成功");
    }

    public static <T> R<T> failed(Integer code, String message) {
        return r(null, code, message);
    }

    public static <T> R<T> failed(String message) {
        return r(null, ErrorCodeEnum.FAIL.getCode(), message);
    }

    public static <T> R<T> failed(ErrorCode ErrorCode) {
        return r(null, ErrorCode.getCode(), ErrorCode.getMessage());
    }

    public static <T> R<T> failed(ErrorCode ErrorCode, String message) {
        return r(null, ErrorCode.getCode(), message);
    }

    public static <T> R<T> r(T data, Integer code, String message) {
        R<T> R = new R<T>();
        R.setCode(code);
        R.setMessage(message);
        if ("".equals(data)) {
            R.setData(null);
        } else {
            R.setData(data);
        }
        return R;
    }
}
